package com.example.demo.sort;

import java.util.Arrays;

/**
 * @author void
 * @date 2022/2/25 16:54
 * @desc 插入排序
 * 类似打扑克抓拍顺序插入
 * 时间复杂度 O(n*n)
 */
public class InsertionSort {

    public static void main(String[] args) {
        int[] nums = {26,3,5,15,6,2};
        int length = nums.length;
        int preIndex,current;
        for(int i=1;i<length;i++){
            preIndex = i-1;
            current = nums[i];
            while (preIndex>=0 && nums[preIndex]>current){
                nums[preIndex+1] = nums[preIndex];
                preIndex--;
            }
            nums[preIndex+1] = current;
            System.out.println(Arrays.toString(nums));
        }
    }
}
